<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Go编译打包 | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="Go编译打包">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/Form/Go%E7%BC%96%E8%AF%91%E6%89%93%E5%8C%85.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Go编译打包">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/Form/Go%E7%BC%96%E8%AF%91%E6%89%93%E5%8C%85.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="Go编译打包">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/11.ff732762.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/24.43e324e1.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link router-link-active">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link router-link-active">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Form</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Form/" aria-current="page" class="sidebar-link">介绍</a></li><li><a href="/Form/Go操作Windows.html" class="sidebar-link">Go操作Windows</a></li><li><a href="/Form/Go爬虫.html" class="sidebar-link">Go爬虫</a></li><li><a href="/Form/Go笔记.html" class="sidebar-link">Go笔记</a></li><li><a href="/Form/Go编译打包.html" class="active sidebar-link">Go编译打包</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Form/Go编译打包.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/Form/Go编译打包.html#第三方库" class="sidebar-link">第三方库</a></li><li class="sidebar-sub-header"><a href="/Form/Go编译打包.html#embed内嵌文件" class="sidebar-link">embed内嵌文件</a></li><li class="sidebar-sub-header"><a href="/Form/Go编译打包.html#打包命令" class="sidebar-link">打包命令</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="go编译打包"><a href="#go编译打包" class="header-anchor">#</a> Go编译打包</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#第三方库">第三方库</a></li><li><a href="#embed内嵌文件">embed内嵌文件</a></li><li><a href="#打包命令">打包命令</a><ul><li><a href="#设置编译环境">设置编译环境</a></li><li><a href="#windows">windows</a></li><li><a href="#linux">linux</a></li><li><a href="#交叉编译代码">交叉编译代码</a></li></ul></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <ul><li><a href="https://c.isme.pub/2019/01/10/go-static" target="_blank" rel="noopener noreferrer">Go语言-打包静态文件<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <blockquote><p>下载打包脚本<a href="/files/go_7z_pack.bat">go_7z_pack.bat</a>或<a href="/files/go_pack.sh">go_pack.sh</a>文件并保存到项目根目录中，
且修改脚本中的<code>files</code>变量保存执行脚本即可</p></blockquote> <p><strong>cross compile</strong></p> <blockquote><p>交叉编译器（英语：Cross compiler）是指一个在某个系统平台下可以产生另一个系统平台的可执行文件的编译器。
交叉编译器在目标系统平台（开发出来的应用程序序所运行的平台）难以或不容易编译时非常有用。</p></blockquote> <blockquote><p>交叉编译是在一个平台上生成另一个平台上的可执行代码。同一个体系结构可以运行不同的操作系统；
同样，同一个操作系统也可以在不同的体系结构上运行。</p></blockquote> <h2 id="第三方库"><a href="#第三方库" class="header-anchor">#</a> 第三方库</h2> <ul><li><a href="https://github.com/mitchellh/gox" target="_blank" rel="noopener noreferrer">https://github.com/mitchellh/gox<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/wheelcomplex/goxx" target="_blank" rel="noopener noreferrer">https://github.com/wheelcomplex/goxx<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/goreleaser/goreleaser" target="_blank" rel="noopener noreferrer">https://github.com/goreleaser/goreleaser<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/laher/goxc" target="_blank" rel="noopener noreferrer">https://github.com/laher/goxc<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/karalabe/xgo" target="_blank" rel="noopener noreferrer">https://github.com/karalabe/xgo<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/techknowlogick/xgo" target="_blank" rel="noopener noreferrer">https://github.com/techknowlogick/xgo<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/storyicon/gos" target="_blank" rel="noopener noreferrer">https://github.com/storyicon/gos<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/docker/golang-cross" target="_blank" rel="noopener noreferrer">https://github.com/docker/golang-cross<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/im4x5yn74x/dropper2" target="_blank" rel="noopener noreferrer">https://github.com/im4x5yn74x/dropper2<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>Go编译器 <a href="https://github.com/tinygo-org/tinygo" target="_blank" rel="noopener noreferrer">https://github.com/tinygo-org/tinygo<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/llvm/llvm-project" target="_blank" rel="noopener noreferrer">https://github.com/llvm/llvm-project<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>嵌入静态资源</strong></p> <ul><li><a href="https://github.com/go-bindata/go-bindata" target="_blank" rel="noopener noreferrer">https://github.com/go-bindata/go-bindata<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/caixw/gobuild" target="_blank" rel="noopener noreferrer">https://github.com/caixw/gobuild<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/shuLhan/go-bindata" target="_blank" rel="noopener noreferrer">https://github.com/shuLhan/go-bindata<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/elazarl/go-bindata-assetfs" target="_blank" rel="noopener noreferrer">https://github.com/elazarl/go-bindata-assetfs<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/rakyll/statik" target="_blank" rel="noopener noreferrer">https://github.com/rakyll/statik<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/GeertJohan/go.rice" target="_blank" rel="noopener noreferrer">https://github.com/GeertJohan/go.rice<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/mjibson/esc" target="_blank" rel="noopener noreferrer">https://github.com/mjibson/esc<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/UnnoTed/fileb0x" target="_blank" rel="noopener noreferrer">https://github.com/UnnoTed/fileb0x<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/gobuffalo/packr" target="_blank" rel="noopener noreferrer">https://github.com/gobuffalo/packr<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/alecthomas/gobundle" target="_blank" rel="noopener noreferrer">https://github.com/alecthomas/gobundle<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/go-playground/statics" target="_blank" rel="noopener noreferrer">https://github.com/go-playground/statics<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/knadh/stuffbin" target="_blank" rel="noopener noreferrer">https://github.com/knadh/stuffbin<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/omeid/go-resources" target="_blank" rel="noopener noreferrer">https://github.com/omeid/go-resources<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/phogolabs/parcello" target="_blank" rel="noopener noreferrer">https://github.com/phogolabs/parcello<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/pyros2097/go-embed" target="_blank" rel="noopener noreferrer">https://github.com/pyros2097/go-embed<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/shurcooL/vfsgen" target="_blank" rel="noopener noreferrer">https://github.com/shurcooL/vfsgen<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/wlbr/templify" target="_blank" rel="noopener noreferrer">https://github.com/wlbr/templify<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://perkeep.org/pkg/fileembed" target="_blank" rel="noopener noreferrer">https://perkeep.org/pkg/fileembed<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/kevinburke/go-bindata" target="_blank" rel="noopener noreferrer">https://github.com/kevinburke/go-bindata<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/markbates/pkger" target="_blank" rel="noopener noreferrer">https://github.com/markbates/pkger<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="embed内嵌文件"><a href="#embed内嵌文件" class="header-anchor">#</a> embed内嵌文件</h2> <ul><li><a href="https://github.com/golang/proposal/blob/master/design/draft-embed.md" target="_blank" rel="noopener noreferrer">https://github.com/golang/proposal/blob/master/design/draft-embed.md<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>go:embed扩展 <a href="https://github.com/alimy/embedx" target="_blank" rel="noopener noreferrer">https://github.com/alimy/embedx<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <blockquote><p>在go1.6版本之前要想把资源文件嵌入到编译的二进制包中必须用第三方包（除非你自己有实现），要么把所有文件压缩在一起</p></blockquote> <ul><li>embed一共有三种数据格式</li></ul> <table><thead><tr><th>数据类型</th> <th>说明</th></tr></thead> <tbody><tr><td>[]byte</td> <td>表示数据存储为二进制格式，如果只使用[]byte和string需要以import (_ &quot;embed&quot;)的形式引入embed标准库</td></tr> <tr><td>string</td> <td>表示数据被编码成utf8编码的字符串，因此不要用这个格式嵌入二进制文件比如图片，引入embed的规则同[]byte</td></tr> <tr><td>embed.FS</td> <td>表示存储多个文件和目录的结构，[]byte和string只能存储单个文件</td></tr></tbody></table> <ul><li><a href="https://mp.weixin.qq.com/s/SiCTV7R2wA_I2nCQkC3GGQ" target="_blank" rel="noopener noreferrer">Go1.16 中发布的内嵌静态资源功能<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/apocelipes/p/13907858.html" target="_blank" rel="noopener noreferrer">golang1.16内嵌静态资源指南<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="打包命令"><a href="#打包命令" class="header-anchor">#</a> 打包命令</h2> <ul><li><a href="https://golang.google.cn/doc/install/source#environment" target="_blank" rel="noopener noreferrer">https://golang.google.cn/doc/install/source#environment<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63" target="_blank" rel="noopener noreferrer">https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h3 id="设置编译环境"><a href="#设置编译环境" class="header-anchor">#</a> 设置编译环境</h3> <ul><li><a href="https://github.com/golang/go/blob/master/src/cmd/dist/build.go#L1513" target="_blank" rel="noopener noreferrer">https://github.com/golang/go/blob/master/src/cmd/dist/build.go#L1513<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><code>go tool dist list</code> 获得所有受支持平台的列表</li> <li><code>GOOS</code> 目标可执行程序运行操作系统，支持<code>darwin</code>、<code>freebsd</code>、<code>linux</code>、<code>windows</code></li> <li><code>GOARCH</code> 目标平台的体系架构，包括<code>386</code>、<code>amd64</code>、<code>arm</code></li> <li><code>CGO_ENABLED</code> CGO开关</li> <li><code>-o</code> 参数为指定输出程序文件名</li> <li><code>go clean -cache</code> 编译完成清理缓存</li></ul> <p><strong><code>-ldflags</code>选项</strong></p> <ul><li>用<code>ldflags</code>给go链接器传入参数，<code>go tool link</code>查看可用值 <a href="https://www.godoc.org/cmd/link" target="_blank" rel="noopener noreferrer">https://golang.org/cmd/link<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <blockquote><p><code>-ldflags=&quot;-w -s&quot;</code> 选项可以减小编译后的程序体积</p></blockquote> <blockquote><p>注意因为<code>date</code>和<code>go version</code>的输出有空格，所以<code>main.BUILD_TIME</code>和<code>main.GO_VERSION</code>必须使用引号括起来</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code>go build -ldflags <span class="token string">&quot;-X main.VERSION=1.0.0 -X 'main.BUILD_TIME=<span class="token variable"><span class="token variable">`</span><span class="token function">date</span><span class="token variable">`</span></span>' \
-X 'main.GO_VERSION=<span class="token variable"><span class="token variable">`</span>go version<span class="token variable">`</span></span>' -X 'main.commitHash=<span class="token variable"><span class="token variable">`</span><span class="token function">git</span> rev-parse HEAD<span class="token variable">`</span></span>'&quot;</span>
</code></pre></div><h3 id="windows"><a href="#windows" class="header-anchor">#</a> windows</h3> <blockquote><p><code>-ldflags=&quot;-H windowsgui&quot;</code> 能隐藏黑窗口</p></blockquote> <div class="language-batch extra-class"><pre class="language-batch"><code># 交叉编译不支持 CGO 所以要禁用它
<span class="token command"><span class="token keyword">SET</span> <span class="token variable">CGO_ENABLED</span><span class="token operator">=</span><span class="token number">0</span></span>
# 打包Linux 执行文件
<span class="token command"><span class="token keyword">SET</span> <span class="token variable">GOOS</span><span class="token operator">=</span>linux</span>
# 打包386执行文件
<span class="token command"><span class="token keyword">SET</span> <span class="token variable">GOARCH</span><span class="token operator">=</span>amd64</span>

<span class="token command"><span class="token keyword">go</span> build main.go</span>
# 打包文件成其他名字
<span class="token command"><span class="token keyword">go</span> build <span class="token parameter attr-name">-o</span> test.exe main.go</span>
</code></pre></div><h3 id="linux"><a href="#linux" class="header-anchor">#</a> linux</h3> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token assign-left variable">CGO_ENABLED</span><span class="token operator">=</span><span class="token number">0</span> <span class="token assign-left variable">GOOS</span><span class="token operator">=</span>windows <span class="token assign-left variable">GOARCH</span><span class="token operator">=</span>amd64 go build main.go
</code></pre></div><h3 id="交叉编译代码"><a href="#交叉编译代码" class="header-anchor">#</a> 交叉编译代码</h3> <div class="language-go extra-class"><pre class="language-go"><code><span class="token keyword">package</span> main

<span class="token keyword">import</span> <span class="token punctuation">(</span>
	<span class="token string">&quot;flag&quot;</span>
	<span class="token string">&quot;fmt&quot;</span>
	<span class="token string">&quot;os&quot;</span>
	<span class="token string">&quot;os/exec&quot;</span>
	<span class="token string">&quot;path&quot;</span>
<span class="token punctuation">)</span>

<span class="token keyword">type</span> syslist <span class="token keyword">struct</span> <span class="token punctuation">{</span>
	GOOS   <span class="token builtin">string</span>
	GOARCH <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token keyword">var</span> syslists <span class="token punctuation">[</span><span class="token number">32</span><span class="token punctuation">]</span>syslist

<span class="token keyword">func</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	syslists<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;darwin&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;darwin&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;dragonfly&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;freebsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;freebsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;freebsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">7</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">9</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;ppc64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;ppc64le&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;mips&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;mipsle&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">14</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;mips64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">15</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;mips64le&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">16</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;linux&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;s390x&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">17</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;nacl&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">18</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;nacl&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64p32&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">19</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;nacl&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">20</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;netbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">21</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;netbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">22</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;netbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">23</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;openbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">24</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;openbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">25</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;openbsd&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;plan9&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">27</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;plan9&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">28</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;plan9&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;arm&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">29</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;solaris&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">30</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;windows&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;386&quot;</span><span class="token punctuation">}</span>
	syslists<span class="token punctuation">[</span><span class="token number">31</span><span class="token punctuation">]</span> <span class="token operator">=</span> syslist<span class="token punctuation">{</span>GOOS<span class="token punctuation">:</span> <span class="token string">&quot;windows&quot;</span><span class="token punctuation">,</span> GOARCH<span class="token punctuation">:</span> <span class="token string">&quot;amd64&quot;</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// 编译</span>
<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">// 文件存放目录</span>
	<span class="token keyword">var</span> parentFolder <span class="token builtin">string</span>
	<span class="token comment">// 编译输出存放的子目录</span>
	<span class="token keyword">var</span> subFolder <span class="token builtin">string</span>
	<span class="token comment">// 文件名前缀</span>
	<span class="token keyword">var</span> filePrefix <span class="token builtin">string</span>
	<span class="token comment">// 要编译的源文件列表</span>
	<span class="token keyword">var</span> files <span class="token builtin">string</span>
	<span class="token comment">// scanner := bufio.NewScanner(os.Stdin)</span>
	<span class="token comment">// scanner.Scan()</span>
	<span class="token comment">// fmt.Println(scanner.Text())</span>
	<span class="token comment">//fmt.Println(&quot;请输文件存放目录：&quot;)</span>
	<span class="token comment">// 当程序到此，会停止执行等待用户输入</span>
	<span class="token comment">//fmt.Scanln(&amp;parentFolder)</span>

	flag<span class="token punctuation">.</span><span class="token function">StringVar</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>parentFolder<span class="token punctuation">,</span> <span class="token string">&quot;p&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;文件存放目录，默认：当前目录&quot;</span><span class="token punctuation">)</span>
	flag<span class="token punctuation">.</span><span class="token function">StringVar</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>subFolder<span class="token punctuation">,</span> <span class="token string">&quot;s&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;编译输出存放子目录，默认：空&quot;</span><span class="token punctuation">)</span>
	flag<span class="token punctuation">.</span><span class="token function">StringVar</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>filePrefix<span class="token punctuation">,</span> <span class="token string">&quot;fp&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;创建文件名前缀，默认：空&quot;</span><span class="token punctuation">)</span>
	flag<span class="token punctuation">.</span><span class="token function">StringVar</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>files<span class="token punctuation">,</span> <span class="token string">&quot;fs&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;源文件列表，默认：空&quot;</span><span class="token punctuation">)</span>
	flag<span class="token punctuation">.</span><span class="token function">Parse</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

	cmde <span class="token operator">:=</span> path<span class="token punctuation">.</span><span class="token function">Join</span><span class="token punctuation">(</span>parentFolder<span class="token punctuation">,</span> subFolder<span class="token punctuation">,</span> filePrefix<span class="token punctuation">)</span>
	<span class="token keyword">if</span> filePrefix <span class="token operator">!=</span> <span class="token string">&quot;&quot;</span> <span class="token operator">&amp;&amp;</span> <span class="token function">len</span><span class="token punctuation">(</span>filePrefix<span class="token punctuation">)</span> <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token punctuation">{</span>
		cmde <span class="token operator">=</span> cmde <span class="token operator">+</span> <span class="token string">&quot;-&quot;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> v <span class="token operator">:=</span> <span class="token keyword">range</span> syslists <span class="token punctuation">{</span>
		ext <span class="token operator">:=</span> <span class="token string">&quot;&quot;</span>
		<span class="token keyword">if</span> v<span class="token punctuation">.</span>GOOS <span class="token operator">==</span> <span class="token string">&quot;windows&quot;</span> <span class="token punctuation">{</span>
			ext <span class="token operator">=</span> <span class="token string">&quot;.exe&quot;</span>
		<span class="token punctuation">}</span>
		thisCmde <span class="token operator">:=</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">&quot;%v%v-%v%v&quot;</span><span class="token punctuation">,</span> cmde<span class="token punctuation">,</span> v<span class="token punctuation">.</span>GOOS<span class="token punctuation">,</span> v<span class="token punctuation">.</span>GOARCH<span class="token punctuation">,</span> ext<span class="token punctuation">)</span>
		fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>thisCmde<span class="token punctuation">)</span>
		cmd <span class="token operator">:=</span> exec<span class="token punctuation">.</span><span class="token function">Command</span><span class="token punctuation">(</span><span class="token string">&quot;go&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;build&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;-ldflags=-w&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;-i&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;-o&quot;</span><span class="token punctuation">,</span> thisCmde<span class="token punctuation">,</span> files<span class="token punctuation">)</span>
		cmd<span class="token punctuation">.</span>Env <span class="token operator">=</span> <span class="token function">append</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span><span class="token function">Environ</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">&quot;GOARCH=&quot;</span><span class="token operator">+</span>v<span class="token punctuation">.</span>GOARCH<span class="token punctuation">,</span> <span class="token string">&quot;GOOS=&quot;</span><span class="token operator">+</span>v<span class="token punctuation">.</span>GOOS<span class="token punctuation">)</span>
		output<span class="token punctuation">,</span> err <span class="token operator">:=</span> cmd<span class="token punctuation">.</span><span class="token function">CombinedOutput</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
		<span class="token keyword">if</span> err <span class="token operator">!=</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
			fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>fmt<span class="token punctuation">.</span><span class="token function">Sprint</span><span class="token punctuation">(</span>err<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;: &quot;</span> <span class="token operator">+</span> <span class="token function">string</span><span class="token punctuation">(</span>output<span class="token punctuation">)</span><span class="token punctuation">)</span>
			<span class="token keyword">return</span>
		<span class="token punctuation">}</span>
		fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">string</span><span class="token punctuation">(</span>output<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span>
	fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;编译完成&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre></div></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//Form/Go编译打包.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/Form/Go笔记.html" class="prev">
        Go笔记
      </a></span> <!----></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/11.ff732762.js" defer></script>
  </body>
</html>
